package com.example.midushop.service.product.impl;

import com.example.midushop.entity.product.find.GetProduct;
import com.example.midushop.entity.product.sku.ProductSKU;
import com.example.midushop.mapper.product.sku.ProductSKUMapper;
import com.example.midushop.service.product.ProductSKUService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 商品SKU服务接口实现类
 */
@Service
public class ProductSKUServiceImpl implements ProductSKUService {
    @Autowired
    ProductSKUMapper productSKUMapper;
    @Override
    public int addProductSKU(long spu_id, String sku_name, String code, String intro, long sales_volume, int quantity, double price, String cover, int status, int is_delete, Date create_time, Date update_time) {
        return productSKUMapper.addProductSKU(spu_id,sku_name,code,intro,sales_volume,quantity,price,cover,status,is_delete,create_time,update_time);
    }

    @Override
    public List<ProductSKU> findProductSKU(long sku_id, long spu_id, String sku_name, String code,int status) {
        return productSKUMapper.findProductSKU(sku_id,spu_id,sku_name,code,status);
    }

    @Override
    public PageInfo<ProductSKU> findProductSKUTwo(long sku_id, long spu_id, String sku_name, String code, int index, int siz,int status) {
        //开始分页，指定页码与每页记录数
        PageHelper.startPage(index,siz);
        //执行查询，请求会被分页插件拦截
        List<ProductSKU> getProductSKU = productSKUMapper.findProductSKU(sku_id,spu_id,sku_name,code,status);
        return new PageInfo<ProductSKU>(getProductSKU);
    }

    @Override
    public PageInfo<ProductSKU> findProductSKUThree(long[] sku_id, long spu_id, String sku_name, String code, int index, int siz, int status) {
        //开始分页，指定页码与每页记录数
        PageHelper.startPage(index,siz);
        //执行查询，请求会被分页插件拦截
        List<ProductSKU> getProductSKUTwo = productSKUMapper.findProductSKUTwo(sku_id,spu_id,sku_name,code,status);
        return new PageInfo<ProductSKU>(getProductSKUTwo);
    }

    @Override
    public int UqProductSKUInfo(List<ProductSKU> productSKUList) {
        int a =0;
        ArrayList<ProductSKU> productSKUS = new ArrayList<>(productSKUList);
        for (int i = 0;i<productSKUS.size();i++){
//               a+=productSKUMapper.UqProductSKU(productSKUS.get(i).sku_id,productSKUS.get(i).spu_id,productSKUS.get(i).sku_name,
//                        productSKUS.get(i).intro,productSKUS.get(i).sales_volume,productSKUS.get(i).quantity,productSKUS.get(i).price,
//                        productSKUS.get(i).cover,productSKUS.get(i).status,productSKUS.get(i).update_time);
        }
        return a;
    }
}
